package com.leyou.item.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.leyou.item.dto.CategoryDTO;
import com.leyou.item.entity.Category;
import com.leyou.item.entity.CategoryBrand;
import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;


@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    //根据分类id，查询商品分类
    @Override
    public CategoryDTO queryCategoryById(Long id) {
        return new CategoryDTO(this.getById(id));
    }


    //根据分类id的集合，查询商品分类的集合
    @Override
    public List<CategoryDTO> queryCategoriesByIds(List<Long> ids) {
//        //创建集合接收商品分类集合
//        List<CategoryDTO> CategoryList = new ArrayList<>();
//        for (Long id : ids) {
//            //直接复用根据分类id，查询商品分类方法
//            CategoryList.add(queryCategoryById(id));
//        }
//        return CategoryList;

        List<Category> categories = listByIds(ids);
        List<CategoryDTO> categoryDTOList = CategoryDTO.convertEntityList(categories);
        return categoryDTOList;
    }


    //根据父类目id，查询子类目的集合
    @Override
    public List<CategoryDTO> queryCategoriesByParentId(Long pid) {
        List<CategoryDTO> CategoryList = baseMapper.queryCategoriesByParentId(pid);
        return CategoryList;
    }
}
